<style lang="less">
  @import './login.less';
</style>

<template>
  <div class="login">
    <div class="login-con">
      <Card icon="log-in" title="欢迎登录" :bordered="false">
        <div class="form-con">
          <login-form @on-success-valid="handleSubmit"></login-form>
        </div>
      </Card>
    </div>
  </div>
</template>

<script>
import LoginForm from '_c/login-form'
import { mapActions } from 'vuex'
import { setToken, getToken } from '@/libs/util'
export default {
  components: {
    LoginForm
  },
  methods: {
    ...mapActions([
      'getUserInfo'
    ]),
    handleSubmit ({ userName, password }) {
        if(userName == 'super_admin'){
            setToken('super_admin');
            let params = {
                name: 'super_admin',
                user_id: '1',
                access: ['super_admin', 'admin'],
                token: 'super_admin',
                avator: 'https://file.iviewui.com/dist/a0e88e83800f138b94d2414621bd9704.png'
            }
            localStorage.setItem('userInfo', JSON.stringify(params));
            this.$store.commit('getUserInfo', params)
        }else{
            setToken('noPrem');
            let params = {
                name: 'noPrem',
                user_id: '0',
                access: ['noPrem'],
                token: 'noPrem',
                avator: 'https://file.iviewui.com/dist/a0e88e83800f138b94d2414621bd9704.png'
            }
            this.$store.commit('getUserInfo', params)
        }
        setTimeout(() => {
            this.$router.push('/')
        }, 1000);
    }
  }
}
</script>

<style>

</style>
